<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public $info;
    public $Book;
    public function __construct() {
        parent::__construct();
        $this->info = M('info');
        $this->Book = M('addbook');
    }

    public function index(){		
        $this->info();
        $this->newBook();
        $this->shuxiangBook();
        $this->kaijuanBook();
        $this->zhiyongBook();
        $this->guessBook();
        $this->tuijianBook();		
        $this->display();
    }
    public function info() {
    	$info = $this->info->select();
    	$this->assign('info',$info);
    }     

    public function newBook() {
          $newBook =  $this->Book->field('id,title,suotu')->
                      order('id desc')->limit(10)->select();
          $newBook1= array_slice($newBook, 0,3);
          $this->assign('newBook1',$newBook1);
          $newBook2= array_slice($newBook, 3,3);
          $this->assign('newBook2',$newBook2);
          $newBook3= array_slice($newBook, 6,3);
          $this->assign('newBook3',$newBook3);
    }

    public function guessBook() {
         $id_arr = $this->Book->field('id')->select();
         shuffle($id_arr);  //打乱数组
         $arr= array_slice($id_arr, 1,10); //截取数组从1开始的3个元素作为数组
          $ids = array();
         foreach ($arr as $k => $v) {   //把二维数组转化为一维数组
             $ids[] = $v['id'];
         }
          $map['id'] = array('in',$ids);
           $guessBook = $this->Book->field('id,title,suotu')->where($map)->select();
           shuffle($guessBook);
          $guessBook1= array_slice($guessBook, 1,3);
          $this->assign('guessBook1',$guessBook1);
          $guessBook2= array_slice($guessBook, 4,3);
          $this->assign('guessBook2',$guessBook2);
          $guessBook3= array_slice($guessBook, 7,3);
          $this->assign('guessBook3',$guessBook3);
    }    

    public function tuijianBook() {
        $id_arr = $this->Book->field('id')->select();
         shuffle($id_arr);  //打乱数组
         $arr= array_slice($id_arr, 2,5); //截取数组1-3个元素作为数组
          $ids = array();
         foreach ($arr as $k => $v) {   //把二维数组转化为一维数组
             $ids[] = $v['id'];
         }
          $map['id'] = array('in',$ids);
           $tuijianBook = $this->Book->field('id,title,suotu,writer,note')->where($map)->select();
           shuffle($tuijianBook);
          $this->assign('tuijianBook',$tuijianBook);
    }

    public function shuxiangBook() {
          
        $map['sid'] = array('in',array('17','5','13','4'));
        $shuxiangBook = $this->Book->field('id,title,suotu,writer')->where($map)->select();
        shuffle($shuxiangBook);
          $shuxiangBook1= array_slice($shuxiangBook, 1,3);
          $this->assign('shuxiangBook1',$shuxiangBook1);
          $shuxiangBook2= array_slice($shuxiangBook, 4,3);
          $this->assign('shuxiangBook2',$shuxiangBook2);
          $shuxiangBook3= array_slice($shuxiangBook, 7,3);
          $this->assign('shuxiangBook3',$shuxiangBook3);   

    }

    public function zhiyongBook() {
        $map['sid'] = array('in',array('7','10','6','12'));
        $zhiyongBook = $this->Book->field('id,title,suotu,writer')->where($map)->select();
        shuffle($zhiyongBook);
         
          $zhiyongBook1= array_slice($zhiyongBook, 1,3);
          $this->assign('zhiyongBook1',$zhiyongBook1);
          $zhiyongBook2= array_slice($zhiyongBook, 4,3);
          $this->assign('zhiyongBook2',$zhiyongBook2);
          $zhiyongBook3= array_slice($zhiyongBook, 7,3);
          $this->assign('zhiyongBook3',$zhiyongBook3); 

    }

    public function kaijuanBook() {
        $map['sid'] = array('in',array('8','25','11','9'));
        $kaijuanBook = $this->Book->field('id,title,suotu,writer')->where($map)->select();
        shuffle($kaijuanBook);
        
          $kaijuanBook1= array_slice($kaijuanBook, 1,3);
          $this->assign('kaijuanBook1',$kaijuanBook1);
          $kaijuanBook2= array_slice($kaijuanBook, 4,3);
          $this->assign('kaijuanBook2',$kaijuanBook2);
          $kaijuanBook3= array_slice($kaijuanBook, 7,3);
          $this->assign('kaijuanBook3',$kaijuanBook3);
          
    }



    public function lisd(){
         

          $newBook =  $this->Book->field('id,title,suotu,writer')->
                   limit(30)->select();
          shuffle($newBook);
          $this->assign('Book',$newBook);
           
      $this->display();
    }

    public function kaijuan(){
            $map['sid'] = array('in',array('8','25','11','9'));
        $kaijuanBook = $this->Book->field('id,title,suotu,writer')->where($map)->select();
        shuffle($kaijuanBook);
        $this->assign('Book',$kaijuanBook);
        $this->display();  
    }

    public function shuxiang(){
       
        $map['sid'] = array('in',array('17','5','13','4'));
        $shuxiangBook = $this->Book->field('id,title,suotu,writer')->where($map)->select();
        shuffle($shuxiangBook);
        $this->assign('Book',$shuxiangBook);
        $this->display();
    }

    Public function zhiyong() {
        $map['sid'] = array('in',array('7','10','6','12'));
        $zhiyongBook = $this->Book->field('id,title,suotu,writer')->where($map)->select();
        shuffle($zhiyongBook);
        $this->assign('Book',$zhiyongBook);
        $this->display();
    }
	

} 